package com.house.dict;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.house.entity.Dict;
import com.house.entity.House;
import com.house.service.HouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;


/**
 * 房屋数据字典
 */
@Component
public class DictHouseImpl extends AbstractDictDataImpl {

    @Autowired
    HouseService houseService;


    @Override
    public List<Dict> execute() {
        List<House> houses = houseService.list(Wrappers.<House>query().orderByDesc("create_time"));

        List<Dict> dices = new ArrayList<>();
        houses.forEach(house -> {
            Dict dict = new Dict();
            dict.setValue(house.getId());
            dict.setText(house.getTitle());
            dices.add(dict);
        });
        return dices;
    }
}
